package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ProductBean;
import com.project.bean.SellOrderBean;
import com.project.bean.UserBean;
import com.project.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("product")
@Api(tags = "库存商品")
public class ProductController {
    @Autowired
    private IProductService productService;
    @ApiOperation(value = "分页查询库存情况")
    @RequestMapping("findByItem")
    public IPage<ProductBean> findByItem(Integer pageNO, String name,
                                         Integer startNum, Integer endNum,
                                         String unsurePrice, String type){
        return productService.findByItem(pageNO, name, startNum, endNum, unsurePrice, type);
    }
    @ApiOperation(value = "根据库存商品id查询库存商品的信息信息")
    @RequestMapping("findById")
    public ProductBean findById(String productId){
        return productService.findById(productId);
    }
    @ApiOperation(value = "根据库存商品id，修改建议销售价格")
    @RequestMapping("update")
    public String update(String productId,Integer outPrice){
        productService.update(productId, outPrice);
        return "ok";
    }
    @ApiOperation(value = "动态分页查询商品库存数量")
    @RequestMapping("findByType")
    public IPage<ProductBean> findByType(Integer pageNO,String name,String type){
        return productService.findByType(pageNO, name, type);
    }
    @ApiOperation(value = "入库")
    @RequestMapping("inset")
    public String inset(String supplierName, HttpServletRequest req){
        UserBean userBean = (UserBean) req.getSession().getAttribute("loginUser");
        productService.inset(supplierName,userBean);
        return "ok";
    }
    @ApiOperation(value = "出库")
    @RequestMapping("outbound")
    public String outbound(SellOrderBean sellOrder, HttpServletRequest req){
        UserBean userBean = (UserBean) req.getSession().getAttribute("loginUser");
        productService.outbound(sellOrder, userBean.getUserId());
        return "ok";
    }
}
